package views;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import bean.Cls;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JMenu;
import java.awt.Color;

public class Main extends JFrame {

    private static final long serialVersionUID = 1L;
    private JPanel contentPane;
    Cls cls2=new Cls();

    JLabel lblNewLabel = new JLabel("请选择班级");

    /**
     * Launch the application.
     * @return
     */
    public  void setCls(Cls cls) {
        cls2=cls;
        lblNewLabel.setText(cls2.getC_name());


    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Main frame = new Main();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public Main() {

        setTitle("登录系统");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

        setContentPane(contentPane);
        contentPane.setLayout(null);

        JMenuBar menuBar = new JMenuBar();
        menuBar.setBounds(0, 0, 436, 23);
        contentPane.add(menuBar);

        JMenu mnNewMenu = new JMenu("文件");
        menuBar.add(mnNewMenu);

        JMenuItem mntmNewMenuItem = new JMenuItem("New menu item");
        mnNewMenu.add(mntmNewMenuItem);

        JMenu mnNewMenu_1 = new JMenu("班级管理");
        menuBar.add(mnNewMenu_1);

        JMenuItem mntmNewMenuItem_3 = new JMenuItem("新增班级");
        mntmNewMenuItem_3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                AddClass addClass=new AddClass();
                addClass.setVisible(true);
                Main.this.dispose();


            }
        });
        mnNewMenu_1.add(mntmNewMenuItem_3);

        JMenuItem mntmNewMenuItem_4 = new JMenuItem("班级列表");
        mntmNewMenuItem_4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ClassList classList=new ClassList();
                classList.setCls(cls2);
                classList.setVisible(true);
                Main.this.dispose();
            }
        });
        mnNewMenu_1.add(mntmNewMenuItem_4);

        JMenu mnNewMenu_2 = new JMenu("小组管理");
        menuBar.add(mnNewMenu_2);

        JMenuItem mntmNewMenuItem_1 = new JMenuItem("新增小组");
        mntmNewMenuItem_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(lblNewLabel.getText().equals("请选择班级")) {
                    JOptionPane.showMessageDialog(null,"请先选择班级","提示",JOptionPane.PLAIN_MESSAGE);
                }else {
                    AddTeam addGroup=new AddTeam();
                    addGroup.setCls(cls2);
                    addGroup.setVisible(true);
                    Main.this.dispose();
                }
            }
        });
        mnNewMenu_2.add(mntmNewMenuItem_1);

        JMenuItem mntmNewMenuItem_2 = new JMenuItem("小组列表");
        mntmNewMenuItem_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(lblNewLabel.getText().equals("请选择班级")) {
                    JOptionPane.showMessageDialog(null,"请先选择班级","提示",JOptionPane.PLAIN_MESSAGE);
                }else {
                    TeamList tlist=new TeamList();
                    tlist.setCls(cls2);
                    tlist.setVisible(true);
                    Main.this.dispose();
                }
            }
        });
        mnNewMenu_2.add(mntmNewMenuItem_2);

        JMenu mnNewMenu_3 = new JMenu("学生管理");
        menuBar.add(mnNewMenu_3);

        JMenuItem mntmNewMenuItem_5 = new JMenuItem("新增学生");
        mntmNewMenuItem_5.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(lblNewLabel.getText().equals("请选择班级")) {
                    JOptionPane.showMessageDialog(null,"请先选择班级","提示",JOptionPane.PLAIN_MESSAGE);
                }else {
                    AddStudent addStudent=new AddStudent();
                    addStudent.setCls(cls2);
                    addStudent.setVisible(true);
                    Main.this.dispose();
                }
            }
        });
        mnNewMenu_3.add(mntmNewMenuItem_5);

        JMenuItem mntmNewMenuItem_6 = new JMenuItem("学生列表");
        mntmNewMenuItem_6.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(lblNewLabel.getText().equals("请选择班级")) {
                    JOptionPane.showMessageDialog(null,"请先选择班级","提示",JOptionPane.PLAIN_MESSAGE);
                }else {
                    StudentList slist=new StudentList();
                    slist.setCls(cls2);
                    slist.setVisible(true);
                    Main.this.dispose();
                }
            }
        });
        mnNewMenu_3.add(mntmNewMenuItem_6);

        JMenu mnNewMenu_4 = new JMenu("课堂管理");
        menuBar.add(mnNewMenu_4);

        JMenuItem mntmNewMenuItem_7 = new JMenuItem("随机小组");
        mntmNewMenuItem_7.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(lblNewLabel.getText().equals("请选择班级")) {
                    JOptionPane.showMessageDialog(null,"请先选择班级","提示",JOptionPane.PLAIN_MESSAGE);
                }else {
                    RandomTeam slist=new RandomTeam();
                    slist.setCls(cls2);
                    slist.setVisible(true);
                    Main.this.dispose();
                }
            }
        });
        mnNewMenu_4.add(mntmNewMenuItem_7);

        JMenuItem mntmNewMenuItem_8 = new JMenuItem("随机学生");
        mntmNewMenuItem_8.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(lblNewLabel.getText().equals("请选择班级")) {
                    JOptionPane.showMessageDialog(null,"请先选择班级","提示",JOptionPane.PLAIN_MESSAGE);
                }else {
                    RandomStudent slist=new RandomStudent();
                    slist.setCls(cls2);
                    slist.setVisible(true);
                    Main.this.dispose();
                }
            }
        });
        mnNewMenu_4.add(mntmNewMenuItem_8);

        lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 30));
        lblNewLabel.setForeground(new Color(255, 0, 0));
        lblNewLabel.setBounds(119, 65, 196, 150);
        contentPane.add(lblNewLabel);

        JLabel lblNewLabel_1 = new JLabel("河北师范大学软件学院出品 盗版必究");
        lblNewLabel_1.setBounds(222, 243, 203, 15);
        contentPane.add(lblNewLabel_1);
    }
}
